<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="all" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="classification" content="" />
<meta name="author" content="" />
<meta name="copyright" content="" />
<script type="text/javascript" src="js/common.js"></script>
</head>
<body>
<script type="text/javascript">
var g_json_data = null;
function changeSubCategorySelect(selectedIndex)
{
    if (typeof selectedIndex == "undefined")
    {
        return false;
    }
    var arr_category = new Array();
    for (var i = 0; i < g_json_data[selectedIndex-1].child.length; ++i)
    {
        getSubCategory(g_json_data[selectedIndex-1].child[i], arr_category);
    }
    
    var obj_select_b = $O("brand_category_b");
    select_removeAllOption(obj_select_b);
    for (var i = 0; i < arr_category.length; ++i)
    {
        select_addOption(obj_select_b, arr_category[i].category_name, arr_category[i].category_id);
    }
    //alert(g_json_data[selectedIndex-1].self.category_name);
}
function select_removeAllOption(obj_select)
{
    if (typeof obj_select == "undefined")
    {
        return false;
    }
    while (obj_select.options.length > 1)
    {
        obj_select.remove(1);
    }
    return true;
}
function getSubCategory(category, arr_category)
{
    if (typeof category == "undefined" || typeof category.self == "undefined")
    {
        return false;
    }
    arr_category.push(category.self);
    if (category.child.length == 0)
    {
        return false;
    }
    else
    {
        for (var i = 0; i < category.child.length; ++i)
        {
            arr_category.push(category.child[i]);
        }
    }
}
function select_addOption(objSelectNow,txt,val){var objOption = parent.document.createElement("OPTION");objOption.text= txt;objOption.value=val;objSelectNow.options.add(objOption);}
function addChildToForm(name, value, form)
{
    if ( typeof name != "string" || typeof value != "string" || typeof form == "undefined" )
    {
        return false;
    }
    var input = document.createElement("input");
    input.name = name;
    input.value = value;
    form.appendChild(input);
}
function newBrand()
{
    var obj_form = $O("brand_form");
    obj_form.action = "http://localhost/jiajia/nanbeihuo/index.php?controller=brand&action=newbrand";
    obj_form.method = "post";
    addChildToForm("callback", "newBrandCallback", obj_form);
    var obj_select_b = $O("brand_category_b");
    var obj_select_a = $O("brand_category_a");
    if ( obj_select_b.options[obj_select_b.selectedIndex].value == "select_category" )
    {
        var brand_category = obj_select_a.options[obj_select_a.selectedIndex].value;
    }
    else
    {
        var brand_category = obj_select_b.options[obj_select_b.selectedIndex].value;
    }
    addChildToForm("brand_category", brand_category, obj_form);
    obj_form.submit();
    /*
    var goods_name  = $O("goods_name").value;
    var goods_no    = $O("goods_no").value;
    var brand    = $O("brand").value;
    var supplier    = $O("supplier").value;
    var category    = $O("category").value;
    var keywords    = $O("keywords").value;
    var forum_url    = $O("forum_url").value;
    var weight    = $O("weight").value;
    var quantity    = $O("quantity").value;
    var unit    = $O("unit").value;
    var color    = $O("color").value;
    var model    = $O("model").value;
    var size    = $O("size").value;
    var description    = $O("description").value;
    var detail    = $O("detail").value;
    var big_imgs    = $O("big_imgs").value;
    var small_imgs    = $O("small_imgs").value;
    var imgs    = $O("imgs").value;
    var articles    = $O("articles").value;
    addChildToForm("controller", "goods", obj_form);
    addChildToForm("action", "uploadgoodsweb", obj_form);
    obj_form.submit();
    */
    
    //var querryString = "goods_name="+goods_name+"&goods_no="
    
    return false;
}
</script>
<form id = "brand_form" name="brand_form" method="post">
<button onclick="newBrand();return false;">提交</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="newBrand();return false;">导出xls</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="newBrand();return false;">xls导入</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="newBrand();return false;">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button onclick="newBrand();return false;">同步</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br/>
<br/>
品牌名<input type="text" name="brand_name" id="brand_name"></input>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
品牌url<input type="text" name="brand_url" id="brand_url"></input>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
所属类目<select id="brand_category_a" onchange="if (this.selectedIndex) changeSubCategorySelect(this.selectedIndex);"><option value="root_category" id="root">root</option></select><select id="brand_category_b" ><option value="select_category" id="select_category">请选择所属类目</option></select>
<br/>
<br/>
</form>
<br/>
<script type="text/javascript">
function fillAct(json_data, json_name)
{
    if (typeof json_data == "undefined")
    {
        return false;
    }
    g_json_data = json_data;
    var len = json_data.length;
    var obj_select_a = $O("brand_category_a");
    for ( var i = 0; i < len; ++i )
    {
        select_addOption(obj_select_a, json_data[i].self.category_name, json_data[i].self.category_id );
    }
    
}
</script>
<script type="text/javascript" src="http://localhost/jiajia/nanbeihuo/json/json_category_tree.js"></script>
</body>
</html>